package com.heima.controller;

import com.heima.common.PageResponse;
import com.heima.entity.SkuClass;
import com.heima.service.SkuClassService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/api/vm-service")
public class SkuClassController {
    @Autowired
    private SkuClassService classifyService;


    @PostMapping("/skuClass")
    public Boolean add(@RequestBody SkuClass dto){
        return classifyService.add(dto);
    }

    @GetMapping("/skuClass/search")
    public PageResponse ClazzSelect(@RequestParam(value = "pageIndex",required = false,defaultValue = "1") Integer pageIndex,
                                    @RequestParam(value = "pageSize",required = false,defaultValue = "10") Integer pageSize,
                                    @RequestParam(value = "className",required = false) String className){
        return classifyService.listPage(pageIndex,pageSize,className);
    }

    @GetMapping("/skuClass/{classId}")
    public SkuClass getInfo(String clazzId){
        return classifyService.getClazzById(clazzId);
    }

    @PutMapping("/skuClass/{classId}")
    public Boolean updateSkuClazz(String classId,String className){
        return classifyService.updateSku(classId,className);
    }

    @DeleteMapping("/skuClass/{classId}")
    public void deleteSku(String classId){
       classifyService.deleteSku(classId);
    }

}
